scenes = np.load('data/split.npy', allow_pickle=True).item().get(args.split)
print("Split: {}, which contains {} scenes.".format(args.split, len(scenes)))
這邊讀取已經存下來的場景編號'scene_37' 'scene_34' 'scene_817'
res_scenes = list()
for s in scenes:
s_id = s.split('_')[1]
res_scenes.append(int(s_id))
把場景的編號存起來
for scene_idx in res_scenes:
curr_scene = nusc.scene[scene_idx] #現在場景編號
first_sample_token = curr_scene['first_sample_token'] #取出第一個sample token
curr_sample = nusc.get('sample', first_sample_token) # 取出sample的資料
curr_sample_data = nusc.get('sample_data', curr_sample['data']['LIDAR_TOP']) #取出sample中 lidar的資料
save_data_dict_list = list() # for storing consecutive sequences; the data consists of timestamps, points, etc
save_box_dict_list = list() # for storing box annotations in consecutive sequences
save_instance_token_list = list()
adj_seq_cnt = 0
save_seq_cnt = 0 # only used for save data file name
while curr_sample_data['next'] != '':
# Get the synchronized point clouds
all_pc, all_times, trans_matrices = \
LidarPointCloud.from_file_multisweep_bf_sample_data
(nusc, curr_sample_data,return_trans_matrix=True, nsweeps_back=nsweeps_back,nsweeps_forward=nsweeps_forward)
# Store point cloud of each sweep
pc = all_pc.points
_, sort_idx = np.unique(all_times, return_index=True)
unique_times = all_times[np.sort(sort_idx)] # Preserve the item order in unique_times
num_sweeps = len(unique_times)
# 如果沒有足夠的past 跟 future sweeps的話 要跳過一些keyframe
#===================Skipping keyframe==============================
# Make sure we have sufficient past and future sweeps
if num_sweeps != (nsweeps_back + nsweeps_forward):
# Skip some keyframes if necessary
flag = False
for _ in range(num_keyframe_skipped + 1):
if curr_sample['next'] != '':
curr_sample = nusc.get('sample', curr_sample['next'])
else:
flag = True
break
if flag: # No more keyframes
break
else:
curr_sample_data = nusc.get('sample_data', curr_sample['data']['LIDAR_TOP'])
# Reset
adj_seq_cnt = 0
save_data_dict_list = list()
save_box_dict_list = list()
save_instance_token_list = list()
continue
#===================Skipping keyframe==============================
LidarPointCloud.from_file_multisweep_bf_sample_data
:
回傳aggregate完的pointcloud 簡單來說就是把過去的跟未來幾個frame的pointcloud同步到當下的frame 回傳的是很多point cloud組合而成的點雲集合 可以利用unique time來把它還原成對應時間的sweep
# Prepare data dictionary for the next step (ie, generating BEV maps)
save_data_dict = dict()
box_data_dict = dict() # for remapping the instance ids, according to class_map
curr_token_list = list()
for tid in range(num_sweeps):
_time = unique_times[tid]
# 回傳相同元素的index位置
points_idx = np.where(all_times == _time)[0]
_pc = pc[:, points_idx] # 取出對應sweep時間當下的點雲(4,nbr_points)
save_data_dict['pc_' + str(tid)] = _pc
save_data_dict['times'] = unique_times
save_data_dict['num_sweeps'] = num_sweeps
save_data_dict['trans_matrices'] = trans_matrices
# Get the synchronized bounding boxes
# First, we need to iterate all the instances, and then retrieve their corresponding bounding boxes
num_instances = 0 # The number of instances within this sample
corresponding_sample_token = curr_sample_data['sample_token']
corresponding_sample_rec = nusc.get('sample', corresponding_sample_token)
print(save_data_dict.keys())
會有 (pc_0 - pc_44 for test split), times, num_sweeps, trans_matrices